package com.telephone.purchase.dao;

import com.telephone.purchase.entity.LoginUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;


/**
 * Created by unicom on 2019/8/29.
 *
 */
//dao层，写对数据库的操作
//交给springboot管理的注解
public interface UserRepository extends JpaRepository<LoginUser, Long>,JpaSpecificationExecutor<LoginUser> {
    @Query(value = "select * from user where USER_ID = ?1",nativeQuery = true)
    LoginUser findUserById(Long id);

    @Query(value = "select * from user where USER_EMAIL = ?1",nativeQuery = true)
    LoginUser findByEmail(String userEmail);

    @Query(value = "select * from user where PHONE_NUMBER = ?1",nativeQuery = true)
    LoginUser findByPhone(String phoneNumber);

    @Query(value = "SELECT COUNT(USER_ID) FROM `user` WHERE USER_EMAIL = ?1",nativeQuery = true)
    int emailCount(String userEmail);

    @Modifying
    @Query(value = "UPDATE `user` SET USER_PASSWORD = ?1 WHERE PHONE_NUMBER = ?2",nativeQuery = true)
    int updatePwd(String userPassword, String phoneNumber);



}



